import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {},
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			//缓存用户登陆状态
			uni.setStorageSync('userInfo', provider)
			// uni.setStorage({ 
			// 	key: 'userInfo',
			// 	data: provider
			// })	
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorageSync('userInfo');
			// uni.removeStorage({
			// 	key: 'userInfo'
			// })
			//清空本地缓存
			//uni.clearStorage("userInfo")
		}
	},
	actions: {
		updateUserInfo(context,payload){
			context.commit("login",payload)
		}
	},
	getters: {
		userInfo: (state, getters) => {
			return state.uerInfo
		},
	}
})

export default store
